export default {
    data() {
        return {
            firstTime: true,
            total: 0,
            list: [],
            loading: false,
            keys: [],
            device: []
        }
    },
    mounted() { this.keys = Object.keys(this.params) },
    methods: {
        initials() {
            if (this.firstTime) {
                if (this.booltimeButton) {
                    this.searchData.left.forEach(item => {
                        if (item.key === 'DatePicker') {
                            item.value = [this.$Date().subtract(10, 'day'),this.$Date()]
                            if (this.keys.indexOf('start_date')>-1) {
                                this.params.start_date = item.value[0]
                                this.params.end_date = item.value[0]
                            } else {
                                this.params.start_time = item.value[0]
                                this.params.end_time = item.value[1]
                            }
                        } else if (item.key === 'RadioGroup') {
                            item.show.show = true
                        }
                    });
                } else {
                    this.searchData.left.forEach(item => {
                        if (item.key === 'DatePicker') {
                            item.value = [this.$Date(),this.$Date()]
                            if (this.keys.indexOf('start_date')>-1) {
                                this.params.start_date = item.value[0]
                                this.params.end_date = item.value[0]
                            } else {
                                this.params.start_time = item.value[0]
                                this.params.end_time = item.value[1]
                            }
                        } else if (item.key === 'RadioGroup') {
                            item.show.show = false
                        }
                    });
                }
                if (this.ceshiButton) {
                    this.searchData.left.forEach(item => {
                        if (item.key === 'CheckboxGroup') {
                            item.childList.forEach(it=>{
                                if (it.show) it.show = false
                            })
                        }
                    });
                }
                if (this.columnsHeader == 1) {
                    let length = this.columns.length-3
                    let columnsing = { title: "联系次数", key: "contact_count", minWidth: 168 }
                    this.columns.splice(length, 0, columnsing);
                } else if (this.columnsHeader == 2) {
                    let length = this.columns.length-3
                    let columnsing1 = { title: "未联系天数", slot: "contact_time", minWidth: 168 }
                    let columnsing2 = { title: "联系次数", key: "contact_count", minWidth: 168 }
                    this.columns.splice(length, 0, columnsing1,columnsing2);
                }
                this.params.clue_status_id = this.clue_status_id
                this.firstTime = false
                this.askData()
            }
        },
        changeCheckbox() {
            this.params.page = 1
            this.params.have_repeat = 0
            if (this.keys.indexOf('contact_way')>-1) this.params.contact_way = 0
            this.params.clue_status_id = this.clue_status_id
            this.searchData.left.forEach(item => {
                if (item.key === 'CheckboxGroup') {
                    if (item.value.indexOf(1)>-1) this.params.have_repeat = 1
                    else if (item.value.indexOf(2)>-1) this.params.contact_way = 1
                    else if (item.value.indexOf(3)>-1) this.params.clue_status_id = 28
                } else if (item.key === 'DatePicker') {
                    item.value = []
                } else if (item.key === 'RadioGroup') item.value = null
            });
            this.askData()
        },
        changeRadio() {
            this.params.page = 1
            this.searchData.left.forEach(item => {
                if (item.key === 'RadioGroup') {
                    this.searchData.left.forEach(items => {
                        if (items.key === 'DatePicker') {
                            items.value = [this.$Date().subtract(item.value, 'day'),this.$Date()]
                        }
                    });
                }
            });
            this.askData()
        },
        changeDate() {
            this.params.page = 1
            this.searchData.left.forEach(item => {
                if (item.key === 'RadioGroup') {
                    item.value = null
                }
            });
            this.askData()
        },
        changeaskData() {
            this.searchData.left.forEach(item => {
                if (item.id === 11) {
                    if (item.value) {
                        let childLis = this.device.filter((ee) => ee.did === item.value).map((eee) => {
                            return {
                                ...eee,
                                value: eee.wechatid,
                                label: eee.nickname,
                            };
                        });
                        this.searchData.left.forEach(items => {
                            if (items.id === 12) {
                                items.show.show = true
                                items.childList = childLis
                            }
                        });
                    } else {
                        this.searchData.left.forEach(items => {
                            if (items.id === 12) {
                                items.show.show = false
                            }
                        });
                    }
                } else if (item.id === 19) {
                    if (item.value) {
                        let childLis = this.device.filter(ee => ee.department_id === item.value).map((vv) => {
                            return {
                                label: vv.wechatno,
                                value: vv.wechatno,
                                ...vv,
                            };
                        });
                        this.searchData.left.forEach(items => {
                            if (items.id === 20) {
                                items.childList = childLis
                            }
                        });
                    } else {
                        this.searchData.left.forEach(items => {
                            if (items.id === 20) {
                                items.childList = []
                            }
                        });
                    }
                } else if (item.id === 23) {
                    if (item.value) {
                        let childLis = this.device.filter(ee => ee.department_id === item.value)
                        this.searchData.left.forEach(items => {
                            if (items.id === 24) {
                                items.childList = childLis
                            }
                        });
                    } else {
                        this.searchData.left.forEach(items => {
                            if (items.id === 24) {
                                items.childList = this.device
                            }
                        });
                    }
                }
            });
            this.askData()
        },
        getparams() {
            this.searchData.left.forEach(item => {
                if (item.key === 'Input') {
                    if (this.keys.indexOf('mobile')>-1) this.params.mobile = item.value
                    else this.params.keyword = item.value
                } else if (item.key === 'DatePicker') {
                    if (this.keys.indexOf('start_date')>-1) {
                        this.params.start_date = item.value[0]
                        this.params.end_date = item.value[0]
                    } else {
                        this.params.start_time = item.value[0]
                        this.params.end_time = item.value[1]
                    }
                } else if (item.id === 11) {
                    this.params.department_id = item.value;
                } else if (item.id === 12) {
                    this.params.wechatid = item.value;
                } else if (item.id === 13) {
                    this.params.is_call = item.value;
                } else if (item.id === 14) {
                    this.params.operation_id = item.value;
                } else if (item.id === 15) {
                    this.params.unique_id = item.value;
                } else if (item.id === 16) {
                    this.params.contact_member = item.value
                } else if (item.id === 17) {
                    this.params.dialog_mode_id = item.value;
                } else if (item.id === 18) {
                    this.params.source_type = item.value;
                } else if (item.id === 19) {
                    this.params.department_id = item.value;
                } else if (item.id === 20) {
                    this.params.wechatno = item.value;
                } else if (item.id === 21) {
                    this.params.operation_id = item.value;
                }
            });
        },
        searchaskData() {
            this.params.page = 1
            this.params.have_repeat = 0
            this.params.contact_way = 0
            this.params.clue_status_id = this.clue_status_id
            this.searchData.left.forEach(item => {
                if (item.key === 'DatePicker') {
                    item.value = []
                } else if (item.key === 'RadioGroup') {
                    item.value = null
                } else if (item.key === 'CheckboxGroup') {
                    item.value = []
                } else if (item.id === 11) {
                    item.value = ''
                } else if (item.id === 12) {
                    item.value = ''
                    item.show.show = false
                } else if (item.id === 13) {
                    item.value = ''
                } else if (item.id === 14) {
                    item.value = ''
                } else if (item.id === 15) {
                    item.value = ''
                } else if (item.id === 16) {
                    item.value = ''
                } else if (item.id === 17) {
                    item.value = ''
                } else if (item.id === 18) {
                    item.value = ''
                } else if (item.id === 19) {
                    item.value = ''
                } else if (item.id === 20) {
                    item.value = ''
                } else if (item.id === 21) {
                    item.value = ''
                }
            });
            this.askData()
        },
        // 联系
        handleContactClue(row) {
            this.logs(row)
        }
    }
}